package com.heyue.demo.arithmetic.bubble;

import java.util.Arrays;

/**
 * @author fenghe
 * @date 2022/2/23 8:06
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] arr = {1, 3, 5, 7, 9, 2, 4, 6, 8};
        bubbleSort(arr);
        System.err.println(Arrays.toString(arr));
    }

    public static int[] bubbleSort(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if(arr[j] > arr[j + 1]) {
                    arr[j] ^= arr[j + 1];
                    arr[j + 1] ^= arr[j];
                    arr[j] ^= arr[j + 1];
                }
            }
        }
        return arr;
    }
}
